<template>
	<view class="detail-view">
		<view class="top-bar"><uni-navbar :fixed="true" :back="true" color="#fff" title="线索资料详情"></uni-navbar></view>

		<view class="detail-info" v-if="infoClue.id">
			<view class="info-title">
				<view class="title-top">{{ infoClue.title }}</view>
				<view class="title-btm">
					<text class="btm-time">{{ infoClue.createTime }}</text>
				</view>
			</view>
			<view class="info-detail">
				<view class="info-h2">联系电话</view>
				<view>{{ infoClue.contact }}</view>
				<view class="info-h2">线索内容</view>
				<view class="overflow"><uni-parse :content="infoClue.content"></uni-parse></view>
			</view>
		</view>

		<view class="uploader-add" @click="onTts">
			<image v-if="!play" src="/static/img/icon_76.png" mode="widthFix"></image>
			<image src="/static/img/icon_77.gif" v-else mode="widthFix"></image>
		</view>

		<view class="file-list" v-if="fileList.length > 0">
			<view>附件:</view>
			<view class="file-item" v-for="(item, index) in fileList" :key="index" @click="$showLine(item)">
				<view class="file-name clamp">{{ item.name }}</view>
				<view class="right-type">预览</view>
			</view>
		</view>

		<view class="fiexd-btm" v-if="infoClue.isAdopt == 0 && infoClue.nodeStatus == 2 && type == 'motion' && $sysBtns('sqmy_clue_edit')">
			<u-button class="form-btn" type="error" @click="editTo">采用</u-button>
		</view>
		<view class="fiexd-btm" v-if="infoClue.isAdopt == 0 && type == 'sqmy' && $sysBtns('sqmy_clue_edit')">
			<u-button class="form-btn" type="error" @click="editTo">采用</u-button>
		</view>
	</view>
</template>

<script>
import uniParse from '@/components/uni-parse/parse.vue';
import { mapState } from 'vuex';
export default {
	components: {
		uniParse
	},
	data() {
		return {
			typeList: {},
			kindList: {
				1: '个人提案',
				2: '集体提案',
				3: '联名提案'
			},
			id: '',
			type: 'motion',
			fileList: [],
			infoClue: '',
			play: false
		};
	},
	onLoad(option) {
		this.loadLogin();
		this.id = option.id;
		if (option && option.type) {
			this.type = option.type;
		}
		this.loadData();
	},
	onHide() {
		this.$ttsOff();
	},
	onUnload() {
		this.$ttsOff();
	},
	computed: {
		...mapState(['userInfo'])
	},
	methods: {
		loadLogin() {
			if (this.userInfo.Authorization) {
				this.userId = this.userInfo.sysUser.id;
				this.clientCode = this.userInfo.sysUser.clientCode;
			} else {
				this.$logout();
			}
		},
		loadDict(type, list) {
			this.$request('/system/sys-dict/dictList', {
				clientCode: this.clientCode,
				sysDict: {
					dictType: type
				}
			}).then((res) => {
				if (!res.data) {
					return false;
				}
				res.data.forEach((item) => {
					this[list][item.dictValue] = item.dictName;
				});
			});
		},
		loadData() {
			if (this.type == 'motion') {
				this.$request('/tianbanli/motion-clue/detail', {
					id: this.id,
					userId: this.userId
				}).then((res) => {
					this.fileList = res.data.fileList;
					this.infoClue = res.data.motionClue;
				});
			} else {
				this.$request('/sheqingminyi/sqmy-clue/detail', {
					id: this.id,
					userId: this.userId
				}).then((res) => {
					this.fileList = res.data.fileList;
					this.infoClue = res.data.sqmyClue;
				});
			}
		},
		editTo() {
			if (this.type == 'motion') {
				uni.navigateTo({
					url: '/pagesB/proposal/add?type=clue&id=' + this.id
				});
			} else {
				uni.navigateTo({
					url: '/pagesB/will/add?type=clue&id=' + this.id
				});
			}
		},
		onTts() {
			let text = this.infoClue.title;
			text += ',' + this.$parseTime(this.infoClue.createTime, '{y}-{m}-{d}');
			text += ',' + this.$htmlRegx(this.infoClue.content);
			this.$tts(text, this, 500);
		},
		previewImage(idx, images) {
			uni.previewImage({
				current: idx,
				urls: images
			});
		}
	}
};
</script>

<style lang="scss">
.detail-view {
	background-color: #fff;
}

.fiexd-btm {
	position: static;
	border-top: 10rpx solid $u-border-color;
	padding: 30rpx;
}
</style>
